package com.bnlr.lrparking.appui.mine.recentparkrecord;

import android.support.annotation.Nullable;
import android.view.ViewGroup;

import com.bnlr.lrparking.R;
import com.bnlr.lrparking.constant.ConstantFlag;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * description: 最近停车记录 adapter
 * RecentParkRecordAdapter class
 *
 * @author : Licy
 * @date : 2018/12/26
 */
public class RecentParkRecordAdapter extends BaseQuickAdapter<RecentParkRecordBean.DataBean, BaseViewHolder> {

    public interface OnItemClickListener {
        /**
         * Item 点击监听
         *
         * @param position 位置
         */
        void onItemClick(int position);
    }

    public RecentParkRecordAdapter(int layoutResId, @Nullable List<RecentParkRecordBean.DataBean> data) {
        super(layoutResId, data);
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return super.onCreateViewHolder(parent, viewType);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, RecentParkRecordBean.DataBean dataBean) {
        // 停车日期
        baseViewHolder.setText(R.id.item_park_order_time, (dataBean.getBeginTime().split(" "))[0]);
        // 停车记录状态

        if (dataBean.getStatus().equals(ConstantFlag.STRING_FLAG_ONE)) {
            baseViewHolder.setText(R.id.item_car_status, "停车中");
            baseViewHolder.setTextColor(R.id.item_car_status,
                    mContext.getResources().getColor(R.color.text_ea5544));
        } else if (dataBean.getStatus().equals(ConstantFlag.STRING_FLAG_ZERO)) {

            switch (dataBean.getDealStatus()) {
                case "0": {
                    switch (dataBean.getIsUpload()) {
                        case "0":
                            baseViewHolder.setText(R.id.item_car_status, "已支付");
                            baseViewHolder.setTextColor(R.id.item_car_status,
                                    mContext.getResources().getColor(R.color.main_color));
                            break;
                        case "2":
                            baseViewHolder.setText(R.id.item_car_status, "小票审核失败，请重新上传");
                            baseViewHolder.setTextColor(R.id.item_car_status,
                                    mContext.getResources().getColor(R.color.text_ea5544));
                            break;
                        case "1":
                        case "3":
                            baseViewHolder.setText(R.id.item_car_status, "退款中");
                            baseViewHolder.setTextColor(R.id.item_car_status,
                                    mContext.getResources().getColor(R.color.text_ea5544));
                            break;
                        default:
                            break;
                    }
                }
                break;
                case "1": {
                    switch (dataBean.getIsUpload()) {
                        case "0":
                            baseViewHolder.setText(R.id.item_car_status, "去支付");
                            baseViewHolder.setTextColor(R.id.item_car_status,
                                    mContext.getResources().getColor(R.color.text_ea5544));
                            break;
                        case "1":
                            baseViewHolder.setText(R.id.item_car_status, "小票抵车费审核中");
                            baseViewHolder.setTextColor(R.id.item_car_status,
                                    mContext.getResources().getColor(R.color.text_ea5544));
                            break;
                        case "2":
                            baseViewHolder.setText(R.id.item_car_status, "小票抵车费审核失败，去支付");
                            baseViewHolder.setTextColor(R.id.item_car_status,
                                    mContext.getResources().getColor(R.color.text_ea5544));
                            break;
                        case "3":
                            baseViewHolder.setText(R.id.item_car_status, "小票抵车费成功");
                            baseViewHolder.setTextColor(R.id.item_car_status,
                                    mContext.getResources().getColor(R.color.main_color));
                            break;
                        default:
                            break;
                    }
                }
                break;
                case "2":
                    baseViewHolder.setText(R.id.item_car_status, "退款中");
                    baseViewHolder.setTextColor(R.id.item_car_status,
                            mContext.getResources().getColor(R.color.text_ea5544));
                    break;
                case "3":
                    baseViewHolder.setText(R.id.item_car_status, "已退款");
                    baseViewHolder.setTextColor(R.id.item_car_status,
                            mContext.getResources().getColor(R.color.main_color));
                    break;
                default:
                    break;
            }


        }

        // 车牌号
        baseViewHolder.setText(R.id.item_car_number, dataBean.getCarId());
        // 消耗
        baseViewHolder.setText(R.id.item_contribution, dataBean.getShareValue());
        // 停车时间
        baseViewHolder.setText(R.id.item_park_stay_time, dataBean.getBeginTime());
        // 停车场名称
        baseViewHolder.setText(R.id.item_carport_name, dataBean.getName());
        // 停车场地址
        baseViewHolder.setText(R.id.item_carport_address, dataBean.getAddress());
        // 导航点击监听
        baseViewHolder.addOnClickListener(R.id.item_goto_navigation);

    }

}
